/**
 * 
 */
package net.socket;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author Niki
 * @version 创建时间：2017年3月7日 下午10:10:31
 */
public class Server {
    public static void main(String[] args) {
        dataStreamServer() ;
    }
    
    private static void dataStreamServer(){
        try {
            @SuppressWarnings("resource")
            ServerSocket server = new ServerSocket(9000) ;
            while(true){
                Socket socket = server.accept() ;
                DataOutputStream out = new DataOutputStream(socket.getOutputStream()) ;
                DataInputStream in = new DataInputStream(socket.getInputStream()) ;
                while(true){
                    String msg = in.readUTF() ;
                    System.out.println("client send server is:" + msg);
                    if(msg.equals("quit")){
                        out.writeChars("服务端收到了你的消息。");
                        break ;
                    }else{
                        out.writeChars("服务端收到了你的消息。");
                    }
                }
                
                in.close();
                out.close();
                socket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        
    }
}
